<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>用户后台 - 注册</title>
  <!-- Font Awesome -->
  <link rel="stylesheet" href="/static/plugins/fontawesome-free/css/all.min.css">
  <!-- icheck bootstrap -->
  <link rel="stylesheet" href="/static/plugins/icheck-bootstrap/icheck-bootstrap.min.css">
  <!-- Theme style -->
  <link rel="stylesheet" href="/static/dist/css/adminlte.min.css">

  <!-- jQuery -->
  <script src="/static/plugins/jquery/jquery.min.js"></script>
  <!-- Vue -->
  <script type="text/javascript" src="/static/plugins/vue.min.js"></script>
  <!-- Layer -->
  <script type="text/javascript" src="/static/plugins/layer/layer.js"></script>
  <!-- Bootstrap 4 -->
  <script src="/static/plugins/bootstrap/js/bootstrap.bundle.min.js"></script>
  <!-- AdminLTE App -->
  <script src="/static/dist/js/adminlte.min.js"></script>
</head>
<body class="hold-transition register-page">
<div class="register-box">
  <div class="register-logo">
    <a href="javascript:void(0);"><b>用户</b>注册</a>
  </div>

  <div class="card">
    <div class="card-body register-card-body">
      <form id="register_form">
        <div class="input-group mb-3">
          <input type="text" class="form-control" placeholder="账号，长度不得大于15" title="账号，长度不得大于15" id="user">
          <div class="input-group-append">
            <div class="input-group-text">
              <span class="fas fa-user"></span>
            </div>
          </div>
        </div>
        <div class="input-group mb-3">
          <input type="text" class="form-control" placeholder="电子邮箱" id="email">
          <div class="input-group-append">
            <div class="input-group-text">
              <span class="fas fa-envelope"></span>
            </div>
          </div>
        </div>
        <div class="input-group mb-3">
          <input type="text" class="form-control" placeholder="电话" id="tel">
          <div class="input-group-append">
            <div class="input-group-text">
              <span class="fas fa-phone"></span>
            </div>
          </div>
        </div>
        <div class="input-group mb-3">
          <input type="text" class="form-control" placeholder="支付宝账号" id="alipay_user">
          <div class="input-group-append">
            <div class="input-group-text">
              <span class="fas fa-user"></span>
            </div>
          </div>
        </div>
        <div class="input-group mb-3">
          <input type="text" class="form-control" placeholder="支付宝姓名" id="alipay_name">
          <div class="input-group-append">
            <div class="input-group-text">
              <span class="fas fa-user"></span>
            </div>
          </div>
        </div>
        <div class="input-group mb-3">
          <input type="text" class="form-control" placeholder="QQ号" id="qq_number">
          <div class="input-group-append">
            <div class="input-group-text">
              <span class="fas fa-user"></span>
            </div>
          </div>
        </div>
        <div class="input-group mb-3">
          <input type="password" class="form-control" placeholder="密码，长度不得大于20" title="密码，长度不得大于20" id="password">
          <div class="input-group-append">
            <div class="input-group-text">
              <span class="fas fa-lock"></span>
            </div>
          </div>
        </div>
        <div class="input-group mb-3">
          <input type="password" class="form-control" placeholder="重复密码" id="repeat_password">
          <div class="input-group-append">
            <div class="input-group-text">
              <span class="fas fa-lock"></span>
            </div>
          </div>
        </div>
        <div class="input-group mb-3">
          <input type="text" class="form-control" placeholder="推广ID" value="{push_id}" readonly>
          <div class="input-group-append">
            <div class="input-group-text">
              <span class="fas fa-envelope"></span>
            </div>
          </div>
        </div>
        <div class="row">
          <div class="col">
            <button type="button" class="btn btn-primary btn-block" v-on:click="register">注册</button>
          </div>
          <!-- /.col -->
        </div>
      </form>
      <script type="text/javascript">
        var register_loader = null;
        var register_form = new Vue({
          el: '#register_form',
          methods: {
            register: function () {
              var user = $('#user').val();
              var email = $('#email').val();
              var tel = $('#tel').val();
              var alipay_user = $('#alipay_user').val();
              var alipay_name = $('#alipay_name').val();
              var qq_number = $('#qq_number').val();
              var password = $('#password').val();
              var repeat_password = $('#repeat_password').val();
              if (user.length === 0 || email.length === 0 || tel.length === 0 ||
                alipay_user.length === 0 || alipay_name.length === 0 || 
                qq_number.length === 0 || password.length === 0) {
                layer.alert('表单中存在空值', {icon: 0});
                return;
              } else if (user.length > 15 || password.length > 20) {
                layer.alert('账号长度不得大于15，密码长度不得大于20', {icon: 0});
                return;
              } else if (password !== repeat_password) {
                layer.alert('密码与重复密码不相同', {icon: 0});
                return;
              } else if (user.indexOf('\'') !== -1 || email.indexOf('\'') !== -1 || tel.indexOf('\'') !== -1 || alipay_user.indexOf('\'') !== -1 || alipay_name.indexOf('\'') !== -1 || qq_number.indexOf('\'') !== -1 || password.indexOf('\'') !== -1 || user.indexOf('"') !== -1 || email.indexOf('"') !== -1 || tel.indexOf('"') !== -1 || alipay_user.indexOf('"') !== -1 || alipay_name.indexOf('"') !== -1 || qq_number.indexOf('"') !== -1 || password.indexOf('"') !== -1) {
                layer.alert('表单内容不得含有引号', {icon: 0});
                return;
              }
              login_loader = layer.load(1);
              $.ajax({
                url: 'reg',
                type: 'post',
                data: {
                  user: user,
                  email: email,
                  tel: tel,
                  alipay_user: alipay_user,
                  alipay_name: alipay_name,
                  qq_number: qq_number,
                  password: password
                },
                success: function (data) {
                  console.log(data);
                  layer.close(login_loader);
                  var result = data.split(':');
                  if (result.length !== 2) {
                    layer.alert('系统错误：返回非法值', {icon: 2});
                  } else {
                    var status = result[0];
                    if (status === 'fail') {
                      layer.alert('注册失败：' + result[1], {icon: 2});
                    } else {
                      location.href = 'login.html';
                    }
                  }
                },
                error: function (data) {
                  layer.close(login_loader);
                  layer.alert('系统错误：服务器程序错误', {icon: 2});
                  console.error(data.responseText);
                }
              });
            }
          }
        });
      </script>
      <a href="login" class="text-center">登录</a>
    </div>
    <!-- /.form-box -->
  </div><!-- /.card -->
</div>
<!-- /.register-box -->
</body>
</html>
